package com.networklib.task.base;

import com.networklib.TaskResult;
import com.networklib.task.TaskResultCode;
import com.networklib.task.exception.TaskException;

/**
 * Created by ASUS on 2017/6/13.
 */

public abstract class BaseTask extends ATask{
    protected TaskResult setResultFailure(TaskResult taskResult, Exception e) {
        TaskResultCode taskResultCode = TaskResultCode.FAILURE;
        taskResultCode.setOtherMsg(e.getMessage());
        taskResult.setResultCode(taskResultCode);
        return taskResult;
    }

    protected TaskResult setResultFailure(TaskResult taskResult, String message) {
        TaskResultCode taskResultCode = TaskResultCode.FAILURE;
        taskResultCode.setOtherMsg(message);
        taskResult.setResultCode(taskResultCode);
        return taskResult;
    }

    protected TaskResult setSuccessResult(TaskResult taskResult, Object result) {
        taskResult.setResultCode(TaskResultCode.SUCCESS);
        taskResult.setResult(result);
        return taskResult;
    }

    protected TaskResult setDataEmpty(TaskResult taskResult) {
        taskResult.setResultCode(TaskResultCode.DATAEMPTY);
        return taskResult;
    }
}
